<template>

  <div class="app-container">

    <h2 style="text-align: center;">发布新课程</h2>

    <el-steps :active="2" process-status="wait" align-center style="margin-bottom: 40px;">
      <el-step title="填写课程基本信息"/>
      <el-step title="创建课程大纲"/>
      <el-step title="最终发布"/>
    </el-steps>

    <el-button type="text" @click="openChapterDialog()">添加章节</el-button>

    <!-- 章节 -->
    <ul class="chanpterList">
      <li
        v-for="chapter in chapterVideoList"
        :key="chapter.id">
        <p>
          {{ chapter.title }}

          <span class="acts">
<!--                    <el-button style="" type="text" @click="openVideo(chapter.id)">添加小节</el-button>-->
                 <el-button style=""@click="openQuestionDialog(chapter.id)" type="text">试题夹</el-button>
               <el-button style="" type="text" @click="openEditChatper(chapter.id)">编辑</el-button>
                    <el-button type="text" @click="removeChapter(chapter.id)">删除</el-button>
                </span>
        </p>

        <!-- 视频 -->
<!--        <ul class="chanpterList videoList ">-->
<!--          <li-->
<!--            v-for="video in chapter.children"-->
<!--            :key="video.id">-->
<!--            <p>{{ video.title }}-->

<!--              <span class="acts">-->

<!--                    <el-button type="text" @click="openPaperDigo(video.id)">添加试卷</el-button>-->
<!--                    <el-button style=""  type="text" disabled>编辑</el-button>-->
<!--                    <el-button type="text" @click="removeVideo(video.id)">删除</el-button>-->
<!--              </span>-->
<!--            </p>-->

<!--            <ul class="chanpterList videoList paperList" >-->
<!--              <li-->
<!--                v-for="paper in video.children"-->
<!--                :key="paper.id">-->

<!--                <p>-->
<!--                  {{ paper.title }}-->
<!--                  <span class="acts">-->
<!--                    <el-button  type="primary" circle>试卷</el-button>-->
<!--                     <el-button  type="primary" circle v-if="paper.ishaveanswer" >答案</el-button>-->
<!--                    <el-button-group>-->
<!--                      <el-button style=""v-if="!paper.ishaveanswer" @click="openPaperAnswerDigo(paper.id)" >添加答案</el-button>-->
<!--&lt;!&ndash;                      <el-button style="" v-if="paper.ishaveanswer" @click="openPaperAnswerEditDigo(paper.id,video.id)" >编辑</el-button>&ndash;&gt;-->
<!--                          <el-button  v-if="paper.ishaveanswer" @click="removePaperAnswer(paper.id)">删除</el-button>-->
<!--                    </el-button-group>-->
<!--&lt;!&ndash;                     <el-button style="" @click="openPaperEditDigo(paper.id,video.id)" type="text">编辑</el-button>&ndash;&gt;-->
<!--                    <el-button type="text" @click="removePaper(paper.id)">删除</el-button>-->
<!--                  </span>-->
<!--                </p>-->
<!--              </li>-->
<!--            </ul>-->
<!--          </li>-->
<!--        </ul>-->
      </li>
    </ul>
    <div>
      <el-button @click="previous">上一步</el-button>
      <el-button :disabled="saveBtnDisabled" type="primary" @click="next">下一步</el-button>
    </div>


    <el-dialog :visible.sync="dialogQuestion" title="试题夹" width="90%"
    >
      <el-button @click="openQuestionFromDialog">添加试题</el-button>
      <el-button @click="openUpload=!openUpload">以excel形式上传</el-button>
      <el-button @click="openWordUpload=!openWordUpload">上传word解析习题</el-button>
      <el-table
        :data="questions"
        style="width: 90%">
        <el-table-column
          prop="content"
          label="题干"
          style=""
          min-width="400">
        </el-table-column>
        <el-table-column
          prop="answer"
          label="答案"
          width="330">
        </el-table-column>
        <el-table-column
          prop="difficulty"
          label="难度"
          width="90">
        </el-table-column>
        <el-table-column
          prop="useCount"
          label="引用次数"
          width="90">

        </el-table-column>
        <el-table-column
          prop="type"
          label="类型"
          width="90">
        </el-table-column>
        <el-table-column
          prop="title"
          label="名称"
          width="100">
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
            <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteQuestion(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogQuestion = false">关闭</el-button>
       </div>
    </el-dialog>
    <!-- 添加和修改试题表单 -->
    <el-dialog :visible.sync="dialogQuestionForm" title="添加试题"
               v-if="dialogQuestionForm">

      <el-button size="small"type="primary"@click="isChoice=!isChoice">切换习题输入类型</el-button>
      <el-divider></el-divider>
      <div v-if="isChoice">
        <el-form :model="question" >
          <el-form-item label="类型">
            <el-select v-model="question.type"  >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="时长/分钟">
            <el-input-number v-model="question.time" :min="0" controls-position="right"/>
          </el-form-item>
          <el-form-item label="排序">
            <el-input-number v-model="question.sort" :min="0" controls-position="right"/>
          </el-form-item>
          <el-form-item label="难度">
            <el-input-number v-model="question.difficulty" :min="1" :max="5" ></el-input-number>
          </el-form-item>
          <el-form-item label="题干">
            <el-input type="textarea" v-model="question.content"></el-input>
          </el-form-item>
          <el-form-item label="答案">
            <el-input type="textarea" v-model="question.answer"></el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="question.title"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogQuestionForm = false">取 消</el-button>
          <el-button type="primary" @click="saveOrUpdateQuestion">确 定</el-button>
        </div>
      </div>
      <div v-else>
        <el-form :model="questionChoice" >
          <el-form-item label="时长/分钟">
            <el-input-number v-model="questionChoice.time" :min="0" controls-position="right"/>
          </el-form-item>
          <el-form-item label="排序">
            <el-input-number v-model="questionChoice.sort" :min="0" controls-position="right"/>
          </el-form-item>
          <el-form-item label="难度">
            <el-input-number v-model="questionChoice.difficulty" :min="1" :max="5" ></el-input-number>
          </el-form-item>
          <el-form-item label="题干">
            <el-input type="textarea" v-model="questionChoice.content"></el-input>
          </el-form-item>
          <el-form-item label="选项A">
            <el-input  v-model="questionChoice.choiceA"></el-input>
          </el-form-item>
          <el-form-item label="选项B">
            <el-input  v-model="questionChoice.choiceB"></el-input>
          </el-form-item>
          <el-form-item label="选项C">
            <el-input  v-model="questionChoice.choiceC"></el-input>
          </el-form-item>
          <el-form-item label="选项D">
            <el-input  v-model="questionChoice.choiceD"></el-input>
          </el-form-item>
          <el-form-item label="答案">
            <el-radio-group v-model="questionChoice.answer">
              <el-radio label="A" ></el-radio>
              <el-radio label="B" ></el-radio>
              <el-radio label="C" ></el-radio>
              <el-radio label="D"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="questionChoice.title"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogQuestionForm = false">取 消</el-button>
          <el-button type="primary" @click="saveChoice">确 定</el-button>
        </div>
      </div>

    </el-dialog>
    <!-- 添加和修改章节表单 -->
    <el-dialog :visible.sync="dialogChapterFormVisible" title="添加章节">
      <el-form :model="chapter" label-width="120px">
        <el-form-item label="章节标题">
          <el-input v-model="chapter.title"/>
        </el-form-item>
        <el-form-item label="章节排序">
          <el-input-number v-model="chapter.sort" :min="0" controls-position="right"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogChapterFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdate">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="openUpload"  v-if="openUpload" title="上传excel" >
      <el-button  size="small" @click="isChoiceButton">{{this.uploadtype}}</el-button>
      <div v-if="isChoiceQuestion">
        <el-form label-width="120px">
          <el-form-item label="信息描述">
            <el-tag type="info">普通类型试题excel模板</el-tag>
            <el-tag>
              <i class="el-icon-download"/>
              <a :href="'/static/uploadquestion.xlsx'">点击下载模版</a>
            </el-tag>
          </el-form-item>
          <el-form-item label="选择Excel">
            <el-upload
              v-if="openUpload"
              ref="upload"
              :auto-upload="false"
              :on-success="fileUploadSuccess"
              :on-error="fileUploadError"
              :disabled="importBtnDisabled"
              :limit="1"
              :data="QuestionUploadVo"
              :action="BASE_API+'/eduservice/edu_question/upload'"
              name="file"
              accept="application/vnd.ms-excel">
              <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              <el-button
                :loading="loading"
                style="margin-left: 10px;"
                size="small"
                type="success"
                @click="submitUpload">上传到服务器</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <div v-else>
        <el-form label-width="120px">
          <el-form-item label="信息描述">
            <el-tag type="info">选择题 excel模板</el-tag>
            <el-tag>
              <i class="el-icon-download"/>
              <a :href="'/static/uploadquestionChoice.xlsx'">点击下载模版</a>
            </el-tag>
          </el-form-item>
          <el-form-item label="选择Excel">
            <el-upload
              ref="upload"
              :auto-upload="false"
              :on-success="fileUploadSuccess"
              :on-error="fileUploadError"
              :disabled="importBtnDisabled"
              :limit="1"
              :data="QuestionUploadVo"
              :action="BASE_API+'/eduservice/edu_question_choice/upload'"
              name="file"
              accept="application/vnd.ms-excel">
              <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
              <el-button
                :loading="loading"
                style="margin-left: 10px;"
                size="small"
                type="success"
                @click="submitUpload">上传到服务器</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="clearfile">清除</el-button>
        <el-button @click="openUpload=false">取 消</el-button>
      </div>
    </el-dialog>
<el-dialog :visible.sync="openWordUpload"  v-if="openWordUpload" title="上传word解析习题" >
  <el-form label-width="120px">
    <el-form-item label="信息描述">
      <el-tag type="info">word模版说明</el-tag>
      <el-tag>
        <i class="el-icon-download"/>
        <a :href="'/static/01.xlsx'">点击下载模版</a>
      </el-tag>
    </el-form-item>
    <el-form-item label="选择要解析的word">
      <el-upload
        ref="uploadword"
        :auto-upload="false"
        :on-success="fileWordUploadSuccess"
        :on-error="fileUploadError"
        :limit="1"
        :data="QuestionUploadVo"
        :action="BASE_API+'/eduservice/edu_upload_word/userWordUpload'"
        name="file"
     >
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button
          :loading="loading"
          style="margin-left: 10px;"
          size="small"
          type="success"
          @click="submitWordUpload">上传到服务器</el-button>
      </el-upload>
    </el-form-item>
  </el-form>
</el-dialog>

    <!-- 添加和修改课时表单 -->
<!--    <el-dialog :visible.sync="dialogVideoFormVisible" title="添加课时">-->
<!--      <el-form :model="video" label-width="120px">-->
<!--        <el-form-item label="课时标题">-->
<!--          <el-input v-model="video.title"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="课时排序">-->
<!--          <el-input-number v-model="video.sort" :min="0" controls-position="right"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="是否免费">-->
<!--          <el-radio-group v-model="video.free">-->
<!--            <el-radio :label="true">免费</el-radio>-->
<!--            <el-radio :label="false">默认</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->

<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button @click="dialogVideoFormVisible = false">取 消</el-button>-->
<!--        <el-button :disabled="saveVideoBtnDisabled" type="primary" @click="saveOrUpdateVideo">确 定</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->

<!--    <el-dialog :visible.sync="dialogPaper" title="试卷添加" width="80%">-->
<!--      <el-form :model="paper" label-width="90px">-->
<!--        <el-form-item label="课时标题">-->
<!--          <el-input v-model="paper.title"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="时长/分钟">-->
<!--          <el-input-number v-model="paper.time"  :min="1" ></el-input-number>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="难度">-->
<!--          <el-rate-->
<!--          v-model="paper.difficulty"-->
<!--            :texts="diff"-->
<!--            :colors="['#99A9BF', '#F7BA2A', '#F56c6c']"-->
<!--            show-text-->
<!--          >-->
<!--          </el-rate>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="排序">-->
<!--          <el-input-number v-model="paper.sort" :min="0" controls-position="right"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="内容">-->
<!--          <tinymce  v-model="paper.content"/>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button @click="dialogPaper = false">取 消</el-button>-->
<!--        <el-button :disabled="savePaperBtnDisabled" type="primary" @click="saveOrUpdatePaper">确 定</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
<!--    <el-dialog :visible.sync="dialogPaperAnswer" title="试卷答案添加" width="80%">-->
<!--      <el-form :model="paperAnswer" label-width="90px">-->
<!--        <el-form-item label="排序">-->
<!--          <el-input-number v-model="paperAnswer.sort" :min="0" controls-position="right"/>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="内容">-->
<!--          <tinymce  v-model="paperAnswer.content"/>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button @click="dialogPaperAnswer = false">取 消</el-button>-->
<!--        <el-button :disabled="savePaperAnswerBtnDisabled" type="primary" @click="saveOrUpdatePaperAnswer">确 定</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>
<script>
import chapter from '@/api/edu/chapter'
//import video from '@/api/edu/video'
import Tinymce from '@/components/Tinymce'
import papere from "../../../api/edu/paper";
import question from "../../../api/edu/question";
export default {
  components:{Tinymce},
  data() {
    return {
      uploadtype:'切换为上传普通类型试题',
      isChoiceQuestion:false,
      QuestionUploadVo:{
        chapterId:'',
      },
      BASE_API: process.env.BASE_API, // 接口API地址
      importBtnDisabled: false, // 按钮是否禁用,
      loading: false,
      isChoice:true,
      options: [{
        value: '填空',
        label: '填空'
      }, {
        value: '判断',
        label: '判断'
      }],
      diff:["无聊","容易","中等","费时","极难"],
      savePaperAnswerBtnDisabled:false,
      savePaperBtnDisabled:false,
      saveBtnDisabled:false,
      openUpload:false,
      openWordUpload:false,
    //  saveVideoBtnDisabled:false,
      courseId:'',//课程id
      chapterVideoList:[],
      questions:[],
      chapter:{ //封装章节数据
        title: '',
        sort: 0
      },
      // video: {
      //   title: '',
      //   sort: 0,
      //   free: 0,
      //   videoSourceId: ''
      // },
       paperflag:'',
      paperAnswer:{
        id:'',
        content:'',
        sort:'',
      },
      paper:{
        id:'',
        title:'',
        courseId:'',
        type:'',
      //  videoId:'',
        time:Number,
        difficulty:1,
        sort:0,
        useCount:'',
        content:'',
        ishaveanswer:''
      },
      chapterId:'',
  //    videoId:'',
      question:{
        id:'',
        title:'',
        content:'',
        answer:'',
        chapterId:'',
     //   videoId:'',
        time:'',
        difficulty:1,
        sort:0,
        useCount:0,
      },
      questionChoice:{
        id:'',
        title:'',
        content:'',
        choiceA:'',
        choiceB:'',
        choiceC:'',
        choiceD:'',
        chapterId:'',
        answer:'',
        //   videoId:'',
        time:'',
        difficulty:1,
        sort:0,
        useCount:0,
      },
      dialogQuestion:false,
      dialogQuestionForm:false,//章节弹框
      dialogChapterFormVisible:false,//章节弹框
    //  dialogVideoFormVisible:false, //小节弹框
      dialogPaper:false,
      dialogPaperAnswer:false,
    }
  },
  created() {
    //获取路由的id值

    if(this.$route.params && this.$route.params.id) {
      this.courseId = this.$route.params.id
      //根据课程id查询章节和小节
      this.getChapterVideo()
    }
  },
  methods:{
    clearfile(){
      this.$refs.upload.clearFiles()


    },
    isChoiceButton(){
      this.isChoiceQuestion=!this.isChoiceQuestion
      if(this.isChoiceQuestion==false){
        this.uploadtype='切换为上传普通类型试题'
      }else{
        this.uploadtype='切换为上传选择题'
      }
    },
    submitWordUpload(){

      this.importBtnDisabled = true
      this.loading = true
      // js: document.getElementById("upload").submit()
      this.$refs.uploadword.submit()
      this.QuestionUploadVo={}
    },
    submitUpload() {
      this.QuestionUploadVo.chapterid=this.chapterId
      this.importBtnDisabled = true
      this.loading = true
      // js: document.getElementById("upload").submit()
      this.$refs.upload.submit()
      this.QuestionUploadVo={}
    },
    //上传成功
    fileWordUploadSuccess(){
      this.loading = false
      this.$message({
        type: 'success',
        message: '上传word成功'
      })
      //跳转课程分类列表
      //路由跳转
      this.openWordUpload=false
      this.$refs.uploadword.clearFiles()
      question.getQuestios(this.chapterId)
    },
    fileUploadSuccess(response) {
      //提示信息
      this.loading = false
      this.$message({
        type: 'success',
        message: '上传习题成功'
      })
      //跳转课程分类列表
      //路由跳转
      this.openUpload=false
      this.clearfile()
      question.getQuestios(this.chapterId)
    },
    //上传失败
    fileUploadError() {
      this.loading = false
      this.$message({
        type: 'error',
        message: '上传文件失败'
      })
    },
    saveChoice(){
    this.addChoiceQuestion()
    },
    addChoiceQuestion(){
        question.addChoiceQuestion(this.questionChoice).then(res=>{
          this.$message({
            type: 'success',
            message: '添加试题成功!'
          });
          this.dialogQuestionForm=false
          this.questionChoice={}
          this.getQuestions(this.chapterId)
        })
    },
    saveOrUpdateQuestion(){
      if(!this.question.id){
        this.addQuestion()
      }else {
        this.updateQuestion()
      }
    },
    updateQuestion(){

    },
    deleteQuestion(id){
      this.$confirm('此操作将删除试题, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {  //点击确定，执行then方法
        //调用删除的方法
        question.deleteQuestion(id)
          .then(response =>{//删除成功
            //提示信息
            this.$message({
              type: 'success',
              message: '删除试题成功!'
            });
            //刷新页面
            this.getQuestions(this.chapterId)
          })
      }) //点击取消，执行catch方法

    },
    addQuestion(){
      this.question.chapterId=this.chapterId
      this.question.videoId=this.videoId
      question.addQuestion(this.question).then(res=>{
        this.dialogQuestionForm=false
        this.$message({
          type: 'success',
          message: '添加试题成功!'
        });
        //刷新页面
        this.question={}
        this.getQuestions(this.chapterId)
      })
    },
    openQuestionDialog(chapterId){
      this.chapterId=chapterId
      this.QuestionUploadVo.chapterId=chapterId
    //  this.videoId=videoId
      this.dialogQuestion=true
        this.getQuestions(chapterId)

    },
    openQuestionFromDialog(videoId){
      this.dialogQuestionForm=true

    },
    getQuestions(chapterId){
      question.getQuestios(chapterId).then(res=>{
        this.questions=res.data.questions

      })
    },
///////////////////////////////////////////////////////////////
//     addPaper(){
//       this.paper.courseId=this.courseId
//
//       papere.addPaper(this.paper).then(res=>{
//         this.dialogPaper = false
//         //提示
//         this.$message({
//           type: 'success',
//           message: '添加试卷成功!'
//         });
//         //刷新页面
//         this.getChapterVideo()
//       })
//     },
//     addPaperAnswer(){
//
//       papere.addPaperAnswer(this.paperAnswer).then(res=>{
//         this.dialogPaperAnswer=false
//         this.$message({
//           type: 'success',
//           message: '添加试卷答案成功!'
//         });
//         //刷新页面
//         this.getChapterVideo()
//       })
//     },
//     removePaper(id){
//       this.$confirm('此操作将删除试卷, 是否继续?', '提示', {
//         confirmButtonText: '确定',
//         cancelButtonText: '取消',
//         type: 'warning'
//       }).then(() => {  //点击确定，执行then方法
//         //调用删除的方法
//         papere.deletePaper(id)
//           .then(response =>{//删除成功
//             //提示信息
//             this.$message({
//               type: 'success',
//               message: '删除试卷成功!'
//             });
//             //刷新页面
//             this.getChapterVideo()
//           })
//       }) //点击取消，执行catch方法
//
//     },
//     removePaperAnswer(id){
//       this.$confirm('此操作将删除试卷答案, 是否继续?', '提示', {
//         confirmButtonText: '确定',
//         cancelButtonText: '取消',
//         type: 'warning'
//       }).then(() => {  //点击确定，执行then方法
//         //调用删除的方法
//         papere.deletePaperAnswer(id)
//           .then(response =>{//删除成功
//             //提示信息
//             this.$message({
//               type: 'success',
//               message: '删除试卷答案成功!'
//             });
//             //刷新页面
//             this.getChapterVideo()
//           })
//       }) //点击取消，执行catch方法
//
//     },
//     updataPaper(){
//       papere.updatePaper(this.paper).then(res=>{
//         this.dialogPaper = false
//         //提示
//         this.$message({
//           type: 'success',
//           message: '修改试卷成功!'
//         });
//         //刷新页面
//         this.getChapterVideo()
//       })
//     },
//     updataPaperAnswer(){
//       papere.updatePaperAnswer(this.paperAnswer).then(res=>{
//         this.dialogPaperAnswer = false
//         //提示
//         this.$message({
//           type: 'success',
//           message: '修改试卷答案成功!'
//         });
//         //刷新页面
//         this.getChapterVideo()
//       })
//     },
//     openPaperDigo(id){
//       this.dialogPaper=true
//
//       this.paper.videoId=id
//
//     },
//     openPaperAnswerDigo(id){
//       this.paperAnswer.id=id
//       this.dialogPaperAnswer=true
//     },
//     openPaperEditDigo(paperId,id){
//       this.dialogPaper=true
//       this.paper.videoId=id
//       papere.getPaper(paperId).then(res=>{
//         this.paper=res.data.paper
//
//       })
//     },
//     openPaperAnswerEditDigo(paperId){
//       this.dialogPaperAnswer=true
//
//       papere.getPaperAnswer(paperId).then(res=>{
//         this.paperAnswer=res.data.paper
//         this.paperflag=1
//       })
//     },
//     saveOrUpdatePaper() {
//       if(!this.paper.id){
//         this.addPaper()
//       }else {
//         this.updataPaper()
//       }
//     },
//     saveOrUpdatePaperAnswer() {
//       if(this.paperAnswer.id){
//         this.addPaperAnswer()
//       }else if(this.paperflag){
//         this.updataPaperAnswer()
//       }
//     },

//==============================小节操作====================================
//     //删除小节
//     removeVideo(id) {
//       this.$confirm('此操作将删除小节, 是否继续?', '提示', {
//         confirmButtonText: '确定',
//         cancelButtonText: '取消',
//         type: 'warning'
//       }).then(() => {  //点击确定，执行then方法
//         //调用删除的方法
//         video.deleteVideo(id)
//           .then(response =>{//删除成功
//             //提示信息
//             this.$message({
//               type: 'success',
//               message: '删除小节成功!'
//             });
//             //刷新页面
//             this.getChapterVideo()
//           })
//       }) //点击取消，执行catch方法
//     },
//     //添加小节弹框的方法
//     openVideo(chapterId) {
//       //弹框
//       this.dialogVideoFormVisible = true
//       //设置章节id
//       this.video.chapterId = chapterId
//     },
//     //添加小节
//     addVideo() {
//       //设置课程id
//       this.video.courseId = this.courseId
//       video.addVideo(this.video)
//         .then(response => {
//           //关闭弹框
//           this.dialogVideoFormVisible = false
//           //提示
//           this.$message({
//             type: 'success',
//             message: '添加小节成功!'
//           });
//           //刷新页面
//           this.getChapterVideo()
//         })
//     },
//     saveOrUpdateVideo() {
//       this.addVideo()
//     },

//==============================章节操作====================================
    //删除章节
    removeChapter(chapterId) {
      this.$confirm('此操作将删除章节, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {  //点击确定，执行then方法
        //调用删除的方法
        chapter.deleteChapter(chapterId)
          .then(response =>{//删除成功
            //提示信息
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            //刷新页面
            this.getChapterVideo()
          })
      }) //点击取消，执行catch方法
    },
    //修改章节弹框数据回显
    openEditChatper(chapterId) {
      //弹框
      this.dialogChapterFormVisible = true
      //调用接口
      chapter.getByChapterById(chapterId)
        .then(response => {
          this.chapter = response.data.chapter
        })
    },
    //弹出添加章节页面
    openChapterDialog() {
      //弹框
      this.dialogChapterFormVisible = true
      //表单数据清空
      this.chapter.title = ''
      this.chapter.sort = 0
    },
    //添加章节
    addChapter() {
      //设置课程id到chapter对象里面
      this.chapter.courseId = this.courseId
      chapter.addChapter(this.chapter)
        .then(response => {
          //关闭弹框
          this.dialogChapterFormVisible = false
          //提示
          this.$message({
            type: 'success',
            message: '添加章节成功!'
          });
          //刷新页面
          this.getChapterVideo()
        })
    },
    //修改章节的方法
    updateChapter() {
      chapter.updateChapter(this.chapter)
        .then(response =>  {
          //关闭弹框
          this.dialogChapterFormVisible = false
          //提示
          this.$message({
            type: 'success',
            message: '修改章节成功!'
          });
          //刷新页面
          this.getChapterVideo()
        })
    },
    saveOrUpdate() {
      if(!this.chapter.id) {
        this.addChapter()
      } else {
        this.updateChapter()
      }
    },
    //根据课程id查询章节和小节
    getChapterVideo() {
      chapter.getNestedTreeList(this.courseId)
        .then(response => {
          this.chapterVideoList = response.data.chapters


        })
    },
    previous() {
      this.$router.push({path:'/course/info/'+this.courseId})
    },
    next() {
      //跳转到第二步
      this.$router.push({path:'/course/publish/'+this.courseId})
    }
  }
}
</script>
<style scoped>
.chanpterList{
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
}
.chanpterList li{
  position: relative;
}
.chanpterList p{
  float: left;
  font-size: 20px;
  margin: 10px 0;
  padding: 10px;
  height: 70px;
  line-height: 50px;
  width: 100%;
  border: 1px solid #DDD;
}
.chanpterList .acts {
  float: right;
  font-size: 14px;
}

.videoList{
  padding-left: 80px;
}
.videoList p{
  float: left;
  font-size: 14px;
  margin: 10px 0;
  padding: 10px;
  height: 60px;
  line-height: 30px;
  width: 100%;
  border: 1px dotted #DDD;
}
.paperList{
  padding-left: 100px;

}
.paperList p{
  height: 55px;
}

</style>
